var type = 0;
var adverId = "";


var page = 1; //默认页数
var pageSize = 10; //每页条数
var total = 0; //总条数
//分页方法
function paging(page, pageSize, total) {
	page = Number(page);

	//最大页数
	var maxPage = Math.ceil(total / pageSize) || 1;
	if(page > maxPage) {
		//取值不能超过maxPage
		page = Math.min(page, maxPage);
		tiaozhuan(param, page, pageSize, adverId, type);
	} else if(page < 1) {
		//取值不能小于1
		page = Math.max(page, 1);
		tiaozhuan(param, page, pageSize, adverId, type);
	} else {
		//	当前页数
		$('.ui-paging-count').val(page);
		//首页的置灰处理
		$('.js-page-first').removeClass('ui-pager-disabled');
		//上一页
		$('.js-page-prev').removeClass('ui-pager-disabled').attr("data-page", page - 1);
		//下一页
		$('.js-page-next').removeClass('ui-pager-disabled').attr("data-page", page + 1);
		//最末页
		$('.js-page-last').removeClass('ui-pager-disabled').attr("data-page", maxPage);
		//总页数显示
		$('.js-page-total').text(maxPage);

		//当前显示多少页的处理
		$(".ui-select-pagesize").val(pageSize);
		//第一页的处理
		if(page == 1) {
			$(".js-page-first").addClass('ui-pager-disabled').attr("data-page", "");
			$(".js-page-prev").addClass('ui-pager-disabled').attr("data-page", "");
		}
		if(page == maxPage) {
			//最后一页的处理
			$(".js-page-last").addClass('ui-pager-disabled').attr("data-page", "");
			$(".js-page-next").addClass('ui-pager-disabled').attr("data-page", "");
		}
	}

};
//下拉选择分页条数的操作
$('.ui-select-pagesize').on("change", function() {
	pageSize = $(this).val();
	tiaozhuan(param, page, pageSize, adverId, type);
});

//跳转到X页  blur
$(".ui-paging-count").on("blur", function() {
	page = $(this).val();
	tiaozhuan(param, page, pageSize, adverId, type);
});

//上一页，下一页，首页，最末页的跳转
$('.ui-pager').on("click", function() {
	page = $(this).attr("data-page");
	tiaozhuan(param, page, pageSize, adverId, type);
});

var type_1=GetQueryString("type");
if(type_1 == "1"){
	$(".data_show1").css("display","block");
	$(".data_show2").css("display","none");
}else{
	$(".data_show1").css("display","none");
	$(".data_show2").css("display","block");
}
function tiaozhuan(param, page, pageSize, adverId, type) {
	var html = "";
	method = "post";
	datas = { page: page, pageSize: pageSize, adverId: adverId, type: type };
	getAgentMsg(param, method, datas);
//	console.log(dataResult);
	
	for(var i = 0; i < dataResult.data.rows.length; i++) {
		var istype = "";
		switch(dataResult.data.rows[i].type){
			case 0:
			  istype = "全部类型";
			  break;
			case 2:
			  istype = "充值";
			  break;
			case 4:
			  istype = "转出";
			  break;
			case 5:
			  istype = "竞价交易利润";
			  break;
			case 6:
			  istype = "保价保量利润";
			  break;
			default:istype = "全部类型";
		}
		if(type_1 == "1"){
			html += "<tr>";
			html += "<td>" + dataResult.data.rows[i].extracTime+ "</td>";
			html += "<td>" + dataResult.data.rows[i].adUserInfoId+ "</td>";
			html += "<td>" + dataResult.data.rows[i].userName+ "</td>";
		}else{
			html += "<tr>";
			html += "<td>" + dataResult.data.rows[i].extractTime+ "</td>";
			html += "<td>" + dataResult.data.rows[i].adUserId+ "</td>";
			html += "<td>" + dataResult.data.rows[i].adComapyName+ "</td>";
		}
		
			html += "<td>" + istype + "</td>";
			html += "<td>" + dataResult.data.rows[i].balance + "</td>";
		html += "</tr>";
	}
	$(".roleList").html(html);
	//之后处理分页
	total = dataResult.data.total;
	paging(page, pageSize, total);
}
//下拉选择类型
function clickFunc(obj){
	$("#isTradeType").text($(obj).text());
	type = $(obj).children().attr("data-wei");
	tiaozhuan(param, page, pageSize, adverId, type);
}


//初始化加载数据
window.onload = function() {
	adverId = GetQueryString("adverId");
	if(type_1 == "1"){
		param = "/agency/fiInformation/tradeByType";
	}else{
		param = "/agency/fiExtractProfit/extractRecord";
	}
	
	tiaozhuan(param, page, pageSize, adverId, type);

}